package cn.iocoder.yudao.module.peizhen.controller.app.staff;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


import cn.iocoder.yudao.module.peizhen.controller.app.staff.vo.*;
import cn.iocoder.yudao.module.peizhen.dal.dataobject.staff.StaffDO;
import cn.iocoder.yudao.module.peizhen.service.staff.StaffService;

@Tag(name = "用户 APP - 陪诊师、护工")
@RestController
@RequestMapping("/peizhen/staff")
@Validated
public class AppStaffController {

    @Resource
    private StaffService staffService;

    @PostMapping("/create")
    @Operation(summary = "创建陪诊师、护工")
    public CommonResult<Integer> createStaff(@Valid @RequestBody AppStaffSaveReqVO createReqVO) {
        return success(staffService.createStaff(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新陪诊师、护工")
    public CommonResult<Boolean> updateStaff(@Valid @RequestBody AppStaffSaveReqVO updateReqVO) {
        staffService.updateStaff(updateReqVO);
        return success(true);
    }

    @PutMapping("/switchStaffOnlie")
    @Operation(summary = "切换在线状态")
    public CommonResult<Boolean> switchStaffOnlie(@Valid @RequestBody AppStaffSaveReqVO updateReqVO) {
        staffService.updateStaffOnlie(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除陪诊师、护工")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteStaff(@RequestParam("id") Integer id) {
        staffService.deleteStaff(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得陪诊师、护工")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppStaffRespVO> getStaff(@RequestParam("id") Long id) {
        StaffDO staff = staffService.getStaff(id);
        return success(BeanUtils.toBean(staff, AppStaffRespVO.class));
    }

    @GetMapping("/getByMobile")
    @Operation(summary = "获得陪诊师、护工")
    @Parameter(name = "mobile", description = "手机号", required = true, example = "1024")
    public CommonResult<AppStaffRespVO> getStaffByMobile(@RequestParam("mobile") String mobile) {
        StaffDO staff = staffService.getStaffByMobile(mobile);
        return success(BeanUtils.toBean(staff, AppStaffRespVO.class));
    }


    @GetMapping("/page")
    @Operation(summary = "获得陪诊师、护工分页")
    public CommonResult<PageResult<AppStaffRespVO>> getStaffPage(@Valid AppStaffPageReqVO pageReqVO) {
        PageResult<StaffDO> pageResult = staffService.getStaffPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppStaffRespVO.class));
    }

}